package hander

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func Upload(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "./files" + file.Filename
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, "./files/"+file.Filename)

	c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传文件成功",
		"data": dst,
	})
}
